from flask  import Blueprint,request,jsonify
import json
from db import db1
bp_cate = Blueprint('cate',__name__)

@bp_cate.route('/cateM',methods=['POST','GET'])
def cateM():
    if request.method=='POST':
        data = request.data
        if data:
            data = json.loads(data)
        else:
            data = request.form
        sql = "insert into cate(name) values('%s')"%(data['name'])
        db1.insert(sql)

        return jsonify({'code':200})
    else:
        sql = "select * from cate"
        res = db1.findall(sql)
        return jsonify({'code':200,'list':res})


